package com.heima.wemedia.service.impl;

import com.heima.apis.schedule.IScheduleClient;
import com.heima.model.schedule.dtos.Task;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.utils.common.JdkSerializeUtil;
import com.heima.wemedia.service.wmNewsTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Slf4j
public class wmNewsTaskServiceImpl implements wmNewsTaskService {

    @Autowired
    private IScheduleClient scheduleClient;

    @Override
    public void addNewsTask(Integer id, Date publishTime) {
        Task task = new Task();
        task.setExecuteTime(publishTime.getTime());
        task.setTaskType(1001);
        task.setPriority(1);
        WmNews wmNews = new WmNews();
        wmNews.setId(id);
        task.setParameters(JdkSerializeUtil.serialize(wmNews));
        scheduleClient.addTask(task);
    }
}
